package com.zhou.gulimall.gateway.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

@Configuration
public class GulimallCorsConfiguration {

    @Bean
    public CorsWebFilter corsWebFilter(){
            //new 跨越对象
           UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
            //new跨越配置对象
            CorsConfiguration corsConfiguration = new CorsConfiguration();

        //配置跨越
        corsConfiguration.addAllowedHeader("*");
        corsConfiguration.addAllowedMethod("*");
        corsConfiguration.addAllowedOrigin("*");//請求來源
        source.registerCorsConfiguration("/**",corsConfiguration);
        corsConfiguration.setAllowCredentials(true);//允许携带cookie进行跨域
        return new CorsWebFilter(source);

    }
}
